// Package utils 提供一系列常用工具
package utils

// response.go
// 对 Gin 的 HTTP 相应进行再封装

import (
	"errors"
	"net/http"

	"github.com/gin-gonic/gin"
)

func Error(c *gin.Context, err error, message string, code int) {
	if err == nil {
		err = errors.New(message)
	}

	c.JSON(code, gin.H{
		"error":   err.Error(),
		"message": message,
	})
}

func BadRequest(c *gin.Context, err error, message string) {
	Error(c, err, message, http.StatusBadRequest)
}

func InternalServerError(c *gin.Context, err error, message string) {
	Error(c, err, message, http.StatusInternalServerError)
}

func Unauthorized(c *gin.Context, err error, message string) {
	Error(c, err, message, http.StatusUnauthorized)
}

func NotFound(c *gin.Context, err error, message string) {
	Error(c, err, message, http.StatusNotFound)
}

func StatusOK(c *gin.Context, err error, message string) {
	Error(c, err, message, http.StatusOK)
}
